package com.admin.business.portalWebsite.venusPortalQuestionBrainstorming;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 不吐不快记录表
 * @create: 2023-11-20 18:20:03
 **/
@Service("venusPortalQuestionBrainstormingService")
@Slf4j
public class VenusPortalQuestionBrainstormingService{

    @Resource
    VenusPortalQuestionBrainstormingDao venusPortalQuestionBrainstormingDao;

    /**
     * 添加不吐不快记录表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者用户ID
     *                   - brainstorming_browse:浏览数量
     *                   - brainstorming_fabulous:点赞数量
     *                   - brainstorming_comment:评论数量
     *                   - brainstorming_problem:一句话叙述问题
     *                   - brainstorming_details:问题详情
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return addVenusPortalQuestionBrainstorming(CDO cdoRequest) {
        venusPortalQuestionBrainstormingDao.addVenusPortalQuestionBrainstorming(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新不吐不快记录表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者用户ID
     *                   - brainstorming_browse:浏览数量
     *                   - brainstorming_fabulous:点赞数量
     *                   - brainstorming_comment:评论数量
     *                   - brainstorming_problem:一句话叙述问题
     *                   - brainstorming_details:问题详情
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return updateVenusPortalQuestionBrainstormingById(CDO cdoRequest) {
        venusPortalQuestionBrainstormingDao.updateVenusPortalQuestionBrainstormingById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除不吐不快记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionBrainstormingById(CDO cdoRequest){
        int count = venusPortalQuestionBrainstormingDao.deleteVenusPortalQuestionBrainstormingById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除不吐不快记录表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionBrainstorming(CDO cdoRequest) {
        int count = venusPortalQuestionBrainstormingDao.deleteVenusPortalQuestionBrainstorming(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取不吐不快记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionBrainstormingById(CDO cdoRequest) {
        CDO cdoMapperResult = venusPortalQuestionBrainstormingDao.getVenusPortalQuestionBrainstormingById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取不吐不快记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionBrainstormingListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionBrainstormingDao.getVenusPortalQuestionBrainstormingListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionBrainstormingDao.getVenusPortalQuestionBrainstormingCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取不吐不快记录表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionBrainstormingListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionBrainstormingDao.getVenusPortalQuestionBrainstormingListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionBrainstormingDao.getVenusPortalQuestionBrainstormingCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
